<template>
  <div class="outsourcing">
    <ul class="menu-swtich">
      <li
        v-for="(item, index) in menu"
        :key="index"
        :class="[switchIndex == index ? 'active' : '']"
        @click="switchFun(index, item.areaCode)"
      >
        {{ item.city }}
      </li>
    </ul>
    <div class="search-box" @keyup.enter="searchFun">
      <i class="iconfont iconsearch1"></i>
      <el-input
        placeholder="输入员工姓名进行搜索"
        class="search"
        v-model.trim="searchContent"
      ></el-input>
    </div>
    <div class="table">
      <el-table
        ref="multipleTable"
        :data="tableData"
        v-loading="loading"
        tooltip-effect="dark"
        style="width: 100%"
        :default-sort="{ prop: 'userName', order: 'descending' }"
      >
        <el-table-column
          prop="userName"
          sortable
          label="姓名"
        ></el-table-column>
        <el-table-column prop="sex" label="性别"></el-table-column>
        <el-table-column prop="cardNo" label="身份证号"></el-table-column>
        <el-table-column prop="phone" label="手机号"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click="handleEdit(scope.row)"
              >补缴</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="current"
        :page-sizes="[6, 12, 24, 36]"
        :page-size="pageSize"
        layout="sizes, prev, pager, next"
        :total="total"
      ></el-pagination>
    </div>
    <!--对话框-->
    <el-dialog
      title="社保/公积金补缴"
      :visible.sync="dialogFormVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :show-close="false"
      center
    >
      <div class="checkbox-box">
        <el-checkbox v-model="isPaySb" disabled>社保</el-checkbox>
        <el-checkbox v-model="isPayGjj">公积金</el-checkbox>
      </div>
      <el-form>
        <el-form-item label="时间">
          <el-select
            v-model="sbYearMonths"
            multiple
            style="margin-left: 20px"
            placeholder="请选择时间"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.value"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="comfirmMonth">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import base from "@/assets/js/base";
import { requestApiPost } from "../api/api";
import { reqRep } from "../report/reqReport";
import { resRep } from "../report/resReport";
export default {
  name: "outsourcing",
  data() {
    return {
      loading: false,
      current: 1,
      total: null,
      pageSize: 6,
      checkList: [],
      isPayGjj: true,
      isPaySb: true,
      isMonth: new Date().getMonth() + 1 > 12 ? 1 : new Date().getMonth() + 1,
      current: new Date().getMonth() + 1 > 12 ? 1 : new Date().getMonth() + 1,
      next: new Date().getMonth() + 2 > 12 ? 1 : new Date().getMonth() + 2,
      isNumber: 0,
      lastYear: new Date().getFullYear() - 1,
      thisYear: new Date().getFullYear(),
      switchIndex: 0,
      searchContent: "",
      menu: [],
      tableData: [],
      dialogFormVisible: false,
      options: [],
      sbYearMonths: [],
      startYear: [],
    };
  },
  methods: {
    handleCurrentChange(e) {
      this.current = e;
      this.getData();
    },
    handleSizeChange(e) {
      this.pageSize = e;
      this.getData();
    },
    goBack() {
      this.$router.push("homePage");
    },
    comfirmMonth() {
      if (this.sbYearMonths.length < 1) {
        this.$message({
          message: "请选择补缴时间",
          type: "warning",
          duration: 1500,
        });
        return;
      }
      base
        .postAjax("/user/payBackSet", {
          userId: this.userId,
          isPayGjj: this.isPayGjj ? 1 : 2,
          city: this.city,
          sbYearMonths: this.sbYearMonths.join(),
          companyId: JSON.parse(sessionStorage.getItem("login")).companyId,
        })
        .then((res) => {
          if (res.data.code == 1) {
            this.$message({
              message: res.data.message,
              type: "success",
              duration: 1500,
            });
            this.dialogFormVisible = false;
            this.searchFun();
          } else {
            this.$message({
              message: res.data.message,
              type: "error",
              duration: 1500,
            });
          }
        });
    },
    monthSelect(date) {
      this.isMonth = date;
    },
    isClick(num) {
      this.isNumber = num;
    },
    switchFun(i, code) {
      this.switchIndex = i;
      this.areaCode = code;
      this.getData();
    },
    handleEdit(obj) {
      this.userId = obj.userId;
      this.city = obj.city;
      this.isPayGjj = true;
      this.sbYearMonths = [];
      this.dialogFormVisible = true;
      this.getYear();
    },
    getAddress() {
      base
        .getAjax("/user/companyAreaList", {
          companyId: JSON.parse(sessionStorage.getItem("login")).companyId,
          month: new Date().getMonth() + 1,
        })
        .then((res) => {
          if (res.data.code == 1) {
            this.menu = res.data.data;
            if (res.data.data.length > 0) {
              //获取列表
              this.areaCode = res.data.data[0].areaCode;
              this.getData();
            } else {
              this.loading = false;
              this.$message({
                message: "没有地区",
                type: "warning",
                duration: 1500,
              });
            }
          } else {
            this.$message({
              message: res.data.message,
              type: "error",
              duration: 1500,
            });
          }
        });
    },
    //获取可补缴年月
    getYear() {
      base
        .getAjax("/user/payBackRule", {
          userId: this.userId,
          companyId: JSON.parse(sessionStorage.getItem("login")).companyId,
          county: "",
        })
        .then((res) => {
          if (res.data.code == 1) {
            if (res.data.data.split(",").length > 0) {
              let newDate = res.data.data.split(",");
              let options = [];
              for (let i = 0; i < newDate.length; i++) {
                let obj = {};
                if (newDate[i]) {
                  obj.value = newDate[i];
                  options.push(obj);
                }
              }
              this.options = options;
            } else {
              this.options = [];
            }
          } else {
            this.$message({
              message: res.data.message,
              type: "error",
              duration: 1500,
            });
          }
        });
    },
    searchFun() {
      this.current = 1;
      this.getData();
    },
    getData() {
      this.loading = true;
      base
        .postAjax("/user/payBackemployeeList", {
          companyId: JSON.parse(sessionStorage.getItem("login")).companyId,
          areaCode: this.areaCode,
          name: this.searchContent,
          pageNum: this.current,
          pageSize: this.pageSize,
        })
        .then((res) => {
          this.loading = false;
          if (res.data.code == 1) {
            this.tableData = res.data.data;
            this.total = parseInt(resReport.data.total);
          } else {
            this.$message({
              message: res.data.message,
              type: "error",
              duration: 1500,
            });
          }
        });
    },
  },
  created() {
    //this.getAddress();
  },
};
</script>
<style scoped>
.header {
  padding: 15px;
  height: 50px;
  box-sizing: border-box;
  font-size: 14px;
  border-bottom: 1px solid #eee;
}
.header .org {
  float: right;
  color: #999;
  cursor: pointer;
}
.header i {
  margin-right: 5px;
}
.monthSwitch {
  padding: 15px;
  height: 50px;
  box-sizing: border-box;
  font-size: 14px;
  border-bottom: 1px solid #eee;
}
.monthSwitch i {
  cursor: pointer;
}
.monthSwitch .tt {
  color: #666;
  cursor: pointer;
}
.monthSwitch span {
  margin-right: 20px;
}
.monthSwitch .mv {
  cursor: pointer;
}
.monthSwitch .mv:hover {
  color: #33ac37;
}
.monthActive {
  color: #33ac37;
}

.monthSwitch .tip {
  float: right;
  margin-right: 0;
  color: #999;
}
.opt-user {
  padding: 20px 15px;
}
.opt-user > section {
  display: inline-block;
  margin-right: 20px;
  cursor: pointer;
}
.opt-user i {
  font-size: 20px;
  margin-right: 5px;
  vertical-align: middle;
}
.opt-user .iconadd1 {
  color: #13cb6e;
}
.opt-user .iconbiaoge-xiazai {
  color: #33ac37;
}
.add-user:hover {
  color: #13cb6e;
}
.input-user:hover {
  color: #33ac37;
}
.menu-swtich {
  height: 50px;
  line-height: 50px;
  border-bottom: 1px solid #eee;
}
.menu-swtich li {
  display: inline-block;
  padding: 0 15px;
  cursor: pointer;
}
.active {
  color: #13cb6e;
  border-bottom: 2px solid #13cb6e;
}
.search-box {
  height: 50px;
  line-height: 50px;
}
.search-box i {
  font-size: 18px;
  margin-left: 15px;
  color: #999;
  vertical-align: middle;
}
.search-box .search {
  display: inline-block;
  width: calc(100% - 36px);
}
.showMoney {
  padding: 30px 15px;
}
.showMoney .sm-h {
  margin-bottom: 40px;
}
.sm-h section {
  display: inline-block;
  margin-right: 20px;
}
.sm-h .month {
  margin-left: 10px;
  color: #999;
}
i {
  color: #999;
  font-size: 16px;
}
.download {
  float: right;
  font-size: 14px;
  margin-right: 0 !important;
}
.sm-f > ul {
  display: inline-block;
  width: 100px;
  margin-right: 15px;
  color: #666;
}
.sm-f-no {
  color: #666;
  font-size: 16px;
  margin-bottom: 5px;
}
.sm-f .value {
  color: #666;
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 5px;
}
.sm-f .button {
  float: right;
  width: 140px;
  color: #999;
  text-align: center;
  height: 50px;
  font-size: 14px;
  line-height: 50px;
}

.table .content {
  display: inline-block;
  border-right: 1px solid #ccc;
}
.table .content:last-child {
  border: none;
}
.table .content > section {
  padding: 10px 15px;
}
.table .content > section span {
  margin-right: 10px;
  display: inline-block;
  width: 80px;
  color: #999;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.table .content > section span:nth-child(2) {
  text-align: center;
}
.table .content > section span:last-child {
  margin-right: 0;
  text-align: center;
}
.rests {
  float: right;
}
.el-checkbox {
  margin-right: 20px;
}

.el-form-item,
.checkbox-box {
  width: 530px;
  margin: 0 auto 22px;
}
.el-form-item .el-select {
  width: 350px;
}
.form-title {
  font-size: 16px;
  font-weight: bold;
  padding-bottom: 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid #eee;
}
</style>
